package com.chw.controller;

import com.chw.common.ChwTS;
import com.chw.model.Value;
import com.chw.service.ValueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/value")
public class ValueController {
    @Autowired
    private ValueService valueService;
    @RequestMapping("queryValue")
    public ChwTS queryValue(Integer id){
        try{
            if (id==null){
               return ChwTS.error(400,"缺少参数");
            }
            return ChwTS.success(valueService.queryValue(id));
        }catch (Exception e){
            return ChwTS.error(500,e.getMessage());
        }

    }
    @RequestMapping("updateValue")
    public ChwTS updateValue(Value value){
        try{
            if (value.getId()==null){
                return ChwTS.error(400,"缺少参数");
            }
            valueService.updateValue(value);
            return ChwTS.success("");
        }catch (Exception e){
            return ChwTS.error(500,e.getMessage());
        }

    }
    @RequestMapping("addValue")
    public ChwTS addValue(Value value){
        try{
            if (value.getValue()==null||value.getAid()==null){
                return ChwTS.error(400,"缺少参数");
            }
            valueService.addValue(value);
            return ChwTS.success("");
        }catch (Exception e){
            return ChwTS.error(500,e.getMessage());
        }

    }
}
